package cn.iocoder.yudao.module.wine.dal.mysql.complaincomment;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.wine.dal.dataobject.businessuser.BusinessUserDO;
import cn.iocoder.yudao.module.wine.dal.dataobject.complaincomment.ComplainCommentDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.wine.controller.app.complaincomment.vo.*;

/**
 * 投诉信息评价 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface ComplainCommentMapper extends BaseMapperX<ComplainCommentDO> {

    default PageResult<ComplainCommentDO> selectPage(AppComplainCommentPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ComplainCommentDO>()
                .eqIfPresent(ComplainCommentDO::getUserId, reqVO.getUserId())
                .eqIfPresent(ComplainCommentDO::getContent, reqVO.getContent())
                .eqIfPresent(ComplainCommentDO::getParentId, reqVO.getParentId())
                .eqIfPresent(ComplainCommentDO::getImageUrl, reqVO.getImageUrl())
                .eqIfPresent(ComplainCommentDO::getComplainId, reqVO.getComplainId())
                .betweenIfPresent(ComplainCommentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ComplainCommentDO::getId));
    }

    default List<AppComplainCommentRespVO> getComplainCommentList(Long complainId) {
        return selectJoinList(AppComplainCommentRespVO.class, new MPJLambdaWrapperX<ComplainCommentDO>()
                .selectAll(ComplainCommentDO.class)
                .selectAs(MemberUserDO::getNickname,AppComplainCommentRespVO::getNickname)
                .selectAs(MemberUserDO::getAvatar,AppComplainCommentRespVO::getAvatar)
                .selectAs(BusinessUserDO::getAreaId,AppComplainCommentRespVO::getAreaId)
                .leftJoin(MemberUserDO.class,MemberUserDO::getId,ComplainCommentDO::getUserId)
                .leftJoin(BusinessUserDO.class,BusinessUserDO::getUserId,ComplainCommentDO::getUserId)
                .eq(ComplainCommentDO::getComplainId,complainId)
        );
    }
}
